# -*- coding: UTF-8 -*-

##########################################################################
#
#   Copyright (c) 2020  Bresee, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################

import json
from termios import TIOCPKT_DATA

from flask import Blueprint
from flask import request
import utils.pgsql.pgvlogrecord as record
from utils.wraps import token, urlcost
import utils.message.response as response
import datetime
from datetime import timedelta, datetime, date
import utils.pgsql.pgactivity as pgactivity
import utils.pgsql.pgtechpay as pgtechpay
import hashlib
import requests
import utils.common.initres as initres
from utils.common.wechat_pay import WxPayV3

import utils.common.httpclient as httpclient
import utils.common.log as log
import base64
import os
import uuid
import shutil
import redis
import utils.pgsql.pgadmin as pgadmin
import utils

record_module = Blueprint("mission_record", __name__, url_prefix="/api/v1/operation/record")

@record_module.route("/wecahat/refund", methods=["GET","POST"])
@token.login_required
@urlcost.cost_count_wraps
def wechat_refund():
    userInfo = token.getUserInfoFromAuth(request.headers["Authorization"])
    dic = json.loads(request.data)
    res = []
    if userInfo["role"] != 1:
        return response.make_response_success(res)
    # if not all([dic['password'],dic['transaction_id'],dic['cashFee']]):
    #     return response.make_response_success(res)
    if dic['password'] != "667788!!":
        return response.make_response_success(res)
    # deal_obj = pgtechpay.Pgtechpay().single_byid(dic['transaction_id'])
    # refund = deal_obj['cashFee']
    refund = dic['cashFee']
    totalFee = dic['totalFee']
    # total = refund # 默认退全款
    WX_Notify_URL = "https://skbjy.skwhjt.com/api/v1/operation/record/wechat/callback"
    w1 = WxPayV3(WX_Notify_URL)
    r1 = w1.refund2(refund=refund,total=totalFee,transaction_id=dic['transaction_id'])
    log.logging.info(f"refund2:{r1}")
    if r1[0] == 200:
        res.append(r1[1])
        pgtechpay.Pgtechpay().update_order_status(dic['transaction_id'], refund=refund, total=totalFee)
    return response.make_response_success(res)

@record_module.route("/wechat/callback", methods=["GET","POST"])
def wechat_callback():
    print(request.data)
    return {
            "code": "SUCCESS"
           }

@record_module.route("/userId/<int:userId>", methods=["GET"])
@token.login_required
@urlcost.cost_count_wraps
def alluserId(userId):

    userInfo = token.getUserInfoFromAuth(request.headers["Authorization"])
    obj = record.PgRecord()
    if userInfo["role"] == 1 or userInfo["role"] == 4:# 或者客服
        res = obj.alluserId(userId)
    elif userInfo["role"] == 2:
        # res = obj.allOperatoruserId(userInfo["operatorId"], userId)
        res = obj.alluserId(userId)
    elif userInfo["role"] == 3:
        res = obj.allCaseuserId(userInfo["caseId"], userId)

    return response.make_response_success(res)

@record_module.route("/userId/bfind/<string:userId>", methods=["GET"])
@token.login_required
@urlcost.cost_count_wraps
def alluserId_b(userId):

    userInfo = token.getUserInfoFromAuth(request.headers["Authorization"])
    obj = record.PgRecord()
    if userInfo["role"] == 1:
        res = obj.alluserId(userId)
    elif userInfo["role"] == 2:
        res = obj.allOperatoruserId(userInfo["operatorId"], userId)
    elif userInfo["role"] == 3:
        res = obj.allCaseuserId(userInfo["caseId"], userId)

    return response.make_response_success(res)


@record_module.route("/", methods=["GET"])
@token.login_required
@urlcost.cost_count_wraps
def all():

    userInfo = token.getUserInfoFromAuth(request.headers["Authorization"])
    obj = record.PgRecord()
    if userInfo["role"] == 1 or userInfo["role"] == 5:
        res = obj.all("", "")
    elif userInfo["role"] == 2:
        # res = obj.allOperator(userInfo["operatorId"], "", "")
        res = obj.all("", "")
    elif userInfo["role"] == 3:
        tmp = userInfo['playground_limit']
        res = obj.allCase(userInfo["caseId"], "", "", tmp)
    elif userInfo["role"] == 4: # 客服
        res = obj.all("", "")
    elif userInfo["role"] == 6: # 城市账号
        res = obj.all("", "")
        obj_admin = utils.pgsql.pgadmin.PgAdmin()
        case_list = obj_admin.get_city_cases(userInfo['adminId'])['caseName']
        res = [i for i in res if i['caseName'] in case_list]
        res = []
    return response.make_response_success(res)


@record_module.route("/", methods=["POST"])
@token.login_required
@urlcost.cost_count_wraps
def casepayall():

    Info = json.loads(request.data)
    userInfo = token.getUserInfoFromAuth(request.headers["Authorization"])
    tmp = userInfo['playground_limit'] if userInfo["role"] == 3 else ""
    obj = record.PgRecord()
    # print(Info)
    # print(
    #     datetime.strptime(Info[3], "%Y-%m-%d"),
    #     datetime.strptime(deviation_date(Info[3], +1), "%Y-%m-%d"),
    # )
    # if Info[3] == "":
    #     strattime = ""
    #     endtime = ""
    # else:
    #     strattime = datetime.strptime(Info[3], "%Y-%m-%d")
    #     endtime = datetime.strptime(deviation_date(Info[3], +1), "%Y-%m-%d")
    if len(Info[3]) == 2:
        strattime = Info[3][0]
        endtime = Info[3][1]
    else:
        grant_date = ''
        if userInfo["role"] == 6:
            grant_date = obj.get_grant_date(userInfo['adminId'])
        strattime = f'{grant_date} 00:00:00'
        endtime = "2099-12-30 23:59:59"
    if Info[0] == "":# 默认加载
        if Info[1] == "1": # 全部合成
            if userInfo["role"] == 1:
                res = obj.all(strattime, endtime)
            elif userInfo["role"] == 2:
                res = obj.allOperator(userInfo["operatorId"], strattime, endtime)
            elif userInfo["role"] == 3:
                res = obj.allCase(userInfo["caseId"], strattime, endtime, limit=tmp)
        if Info[1] == "2":
            if userInfo["role"] == 1:
                res = obj.allpay(strattime, endtime)
            elif userInfo["role"] == 2:
                res = obj.otherpay(
                    "operatorId", userInfo["operatorId"], strattime, endtime
                )
            elif userInfo["role"] == 3:
                res = obj.otherpay("caseId", userInfo["caseId"], strattime, endtime, tmp)
        if Info[1] == "3":
            if userInfo["role"] == 1:
                res = obj.allunpay(strattime, endtime)
            elif userInfo["role"] == 2:
                res = obj.otherunpay(
                    "operatorId", userInfo["operatorId"], strattime, endtime
                )
            elif userInfo["role"] == 3:
                res = obj.otherunpay("caseId", userInfo["caseId"], strattime, endtime,tmp)
    else:
        if Info[2] == "":# 无项目筛选
            if Info[1] == "1":# 全选
                res = obj.allCase(Info[0], strattime, endtime, limit=tmp)
            if Info[1] == "2":
                res = obj.otherpay("caseId", Info[0], strattime, endtime, tmp)
            if Info[1] == "3":
                res = obj.otherunpay("caseId", Info[0], strattime, endtime, tmp)
        else:
            if Info[1] == "1":# 支付状态 1 全部，2成功，3退款
                res = obj.allCaseactive(Info[0], Info[2], strattime, endtime, limit=tmp)
            if Info[1] == "2":
                res = obj.otherpayactive("caseId", Info[0], Info[2], strattime, endtime, tmp)
            if Info[1] == "3":
                res = obj.otherunpayactive(
                    "caseId", Info[0], Info[2], strattime, endtime, tmp
                )

    return response.make_response_success(res)


def deviation_date(date, offsets):
    start_date = datetime.strptime(date, "%Y-%m-%d")
    now_date = timedelta(days=offsets)
    a = start_date + now_date
    return a.strftime("%Y-%m-%d")


@record_module.route("/admin/paycount", methods=["GET"])
def paycount():
    operatorId = ""
    userInfo = token.getUserInfoFromAuth(request.headers["Authorization"])
    if userInfo["role"] in [1, 2]: #1:管理员 2:运营商 3:景区账号
        operatorId = userInfo["operatorId"]
        if operatorId == 0:# 超级管理员，要shuikewenhua账号operatorId：1的权限
            operatorId = 1
        payobj = pgtechpay.Pgtechpay()
        ret = [
            {"name": "日交易量", "count": 0},
            {"name": "日新增量", "count": 0},
            {"name": "周交易量", "count": 0},
            {"name": "周新增量", "count": 0},
            {"name": "月交易量", "count": 0},
            {"name": "月新增量", "count": 0},
            {"name": "下载视频总量", "count": 0},
            {"name": "付费金额总数", "count": 0},
        ]
        now = datetime.now().strftime("%Y-%m-%d")
        payobj.payoperatortime(operatorId, now, deviation_date(now, +1))
        ret[0]["count"] = payobj.payoperatortime(
            operatorId,
            datetime.strptime(now, "%Y-%m-%d"),
            datetime.strptime(deviation_date(now, +1), "%Y-%m-%d"),
        )["count"]
        ret[1]["count"] = (
            ret[0]["count"]
            - payobj.payoperatortime(
                operatorId,
                datetime.strptime(deviation_date(now, -1), "%Y-%m-%d"),
                datetime.strptime(now, "%Y-%m-%d"),
            )["count"]
        )
        theday = date.today()
        weekday = theday.isoweekday()
        start = str(theday - timedelta(days=weekday))
        ret[2]["count"] = payobj.payoperatortime(
            operatorId,
            datetime.strptime(deviation_date(start, +1), "%Y-%m-%d"),
            datetime.strptime(deviation_date(start, +8), "%Y-%m-%d"),
        )["count"]
        ret[3]["count"] = (
            ret[2]["count"]
            - payobj.payoperatortime(
                operatorId,
                datetime.strptime(deviation_date(start, -6), "%Y-%m-%d"),
                datetime.strptime(deviation_date(start, +1), "%Y-%m-%d"),
            )["count"]
        )

        now = now.split("-")[0] + "-" + now.split("-")[1] + "-01"  
        feauter = ""
        old = ""  
        if now.split("-")[1] == "01":
            oldyear = str(int(now.split("-")[0]) - 1)
            old = oldyear + "-12-01"
            feauter = now.split("-")[0] + "-" + str(int(now.split("-")[1]) + 1) + "-01"
        elif now.split("-")[1] == "12":
            old = now.split("-")[0] + "-" + str(int(now.split("-")[1]) - 1) + "-01"
            feauter = str(int(now.split("-")[0]) + 1) + "-01-01"
        else:
            old = now.split("-")[0] + "-" + str(int(now.split("-")[1]) - 1) + "-01"
            feauter = now.split("-")[0] + "-" + str(int(now.split("-")[1]) + 1) + "-01"

        ret[4]["count"] = payobj.payoperatortime(
            operatorId,
            datetime.strptime(now, "%Y-%m-%d"),
            datetime.strptime(feauter, "%Y-%m-%d"),
        )["count"]
        ret[5]["count"] = (
            ret[4]["count"]
            - payobj.payoperatortime(
                operatorId,
                datetime.strptime(old, "%Y-%m-%d"),
                datetime.strptime(now, "%Y-%m-%d"),
            )["count"]
        )

        newcountall = payobj.operatorsum(operatorId)
        ret[6]["count"] = newcountall["count"]
        ret[7]["count"] = round(newcountall["nums"] / 100, 2) if newcountall["nums"] else 0
        # 直接翻倍X2
        for i in ret:
            i['count'] = i['count']*2
        return response.make_response_success(ret)
    else:
        return response.make_response_success_no_data()



@record_module.route("/templete", methods=["POST"])
def templete():
    dic = json.loads(request.data)
    
    end_date = dic["date"][1]
    begin_date = dic["date"][0]

    data = {
        "template": {"totalCount": 0, "dayInfo": []},
    }
    activityName = ""
   
    if dic["tem"] == "":
        return response.make_response_success(data)
    activityobj = pgactivity.PgActivity()
    
    activitydic = activityobj.acitivName(dic["tem"])
   
    if "activityName" in activitydic:
        activityName = activitydic["activityName"]
    else:
        return response.make_response_success(data)

    obj = record.PgRecord()
   
    if dic["type"] == "1":
       
        while end_date >= begin_date:
           
            temcompose = obj.temcompose(
                activityName,
                datetime.strptime(end_date, "%Y-%m-%d"),
                datetime.strptime(deviation_date(end_date, +1), "%Y-%m-%d"),
            )
            data["template"]["totalCount"] += len(temcompose)
            data["template"]["dayInfo"].append(
                {"count": len(temcompose), "time": end_date}
            )
            end_date = deviation_date(end_date, -1)
    else:
        while end_date >= begin_date:
            tempay = obj.tempay(
                activityName,
                datetime.strptime(end_date, "%Y-%m-%d"),
                datetime.strptime(deviation_date(end_date, +1), "%Y-%m-%d"),
            )
            data["template"]["totalCount"] += len(tempay)
            data["template"]["dayInfo"].append({"count": len(tempay), "time": end_date})
            end_date = deviation_date(end_date, -1)

    return response.make_response_success(data)


def mymd5(pw):
    md = hashlib.md5() 
    md.update(pw.encode("utf-8")) 
    return md.hexdigest() 



### 获取小程序侧的资金账单 ;
def shuike_cash(queryurl, caseId, starttime, endtime):
    """
    To get shuike app data ;

    """

    header = {
        "content-type": "application/json",
    }

    url = "https://ylsk.zjskjt.com/" + queryurl

    # 5ZEfRSQylRJw6xnl3s49xvgeSzLk2xod|endDate|2022-07-21|startDate|2022-07-19|JFahqn78xRVH1Jv6KCHvZCefSQ7Jz2Am

    md5string = (
        "5ZEfRSQylRJw6xnl3s49xvgeSzLk2xod|caseId|"
        + str(caseId)
        + "|endDate|"
        + endtime
        + "|startDate|"
        + starttime
        + "|JFahqn78xRVH1Jv6KCHvZCefSQ7Jz2Am"
    )
    data = {
        "appid": "5ZEfRSQylRJw6xnl3s49xvgeSzLk2xod",
        "caseId": str(caseId),
        "startDate": starttime,
        "endDate": endtime,
        "sign": mymd5(md5string),
    }
    ret = {}
    try:
        res = requests.post(url, headers=header, data=json.dumps(data), timeout=20)
    except Exception as e:
        return False, ret
    else:
        if res.status_code == 200:
            return True, json.loads(res.text)["t"]
    return False, ret


@record_module.route("/getuserdata", methods=["POST"])
def getuserdata():
    dic = json.loads(request.data)

    end_date = dic["date"][1]
    begin_date = dic["date"][0]
    endDate = end_date[:4] + end_date[5:7] + end_date[8:]
    beginDate = begin_date[:4] + begin_date[5:7] + begin_date[8:]


    payUsers = {"totalCount": 0, "dayInfo": []}
    payVideos = {"totalCount": 0, "dayInfo": []}
    composeUsers = {"totalCount": 0, "dayInfo": []}
    composeVideos = {"totalCount": 0, "dayInfo": []}
    template = {"totalCount": 0, "dayInfo": []}
    cashFee = {"totalCount": 0, "dayInfo": []}
    share = {"totalCount": 0, "dayInfo": []}
    newadd = {"totalCount": 0, "dayInfo": []}

  
    data = {
        "ref_date": f"{beginDate}-{endDate}",
        "caseId": dic["caseId"],
        "payUsers": payUsers,
        "payVideos": payVideos,
        "composeUsers": composeUsers,
        "composeVideos": composeVideos,
        "template": template,
        "cashFee": cashFee,
        "share": share,
        "newadd": newadd,
    }
    cache = redis.Redis(host='10.206.0.115', port=6379, db=10, password='SKadmin123_456')
    t1 = cache.get(request.headers["Authorization"])  # b'929'
    limit = ""
    if t1:# 已登录用户ID
        admin_id = int(t1)
        obj = pgadmin.PgAdmin()
        user_dic = obj.get(admin_id)
        limit = user_dic['playground_limit']
    #分享用户的数据
    ret, sharedic = shuike_cash("/openapi/vlog/queryShareRecord", dic["caseId"], begin_date, end_date)
    if ret is True:
        data["share"] = sharedic
    #新增用户数据
    ret2, newadddic = shuike_cash("/openapi/vlog/queryUserRegister", dic["caseId"], begin_date, end_date)
    if ret2 is True:
        data["newadd"] = newadddic

    obj = record.PgRecord()
    months = (int(end_date[:4])-int(begin_date[:4]))*12 + int(end_date[5:7])-int(begin_date[5:7])
    # while end_date >= begin_date:
    log.logging.info(f"months:{months}")
    video_list_sql = f'select LEFT("EventTime",10) AS "time",count("recordId"),COUNT(DISTINCT("userId")) as "user" from tbl_vlog_record where "caseId" = {dic["caseId"]} GROUP BY LEFT("EventTime",10);'
    video_list = obj.exec_sql(video_list_sql)
    video_dic = {eq['time']:{"user":eq['user'],"count":eq['count']} for eq in video_list}
    pay_list_sql = f'select LEFT("createTime",10) AS "time",SUM("totalFee") AS "money",COUNT("transactionId"),COUNT(DISTINCT("openId")) as "user" from tbl_techpay where "caseId" = {dic["caseId"]} GROUP BY LEFT("createTime",10);'
    pay_list = obj.exec_sql(pay_list_sql)
    pay_dic = {eq['time']: {"user": eq['user'], "money": eq['money'],"count":eq['count']} for eq in pay_list}
    while begin_date <= end_date:
        #-----------------------------------------------------------------------
        # compose = obj.casecompose(
        #     dic["caseId"],
        #     datetime.strptime(begin_date, "%Y-%m-%d"),
        #     datetime.strptime(deviation_date(begin_date, +1), "%Y-%m-%d"),
        #     limit=limit
        # ) if months < 400 else []
        tmp = video_dic.get(begin_date)
        # data["composeVideos"]["totalCount"] += len(compose)
        data["composeVideos"]["totalCount"] += tmp["count"] if tmp else 0
        data["composeVideos"]["dayInfo"].append(
            {"count": tmp["count"] if tmp else 0, "time": begin_date}
        )
        composeuser = []
  
        # for i in compose:
        #     if i["userId"] not in composeuser:
        #         composeuser.append(i["userId"])
        # data["composeUsers"]["totalCount"] += len(composeuser)
        data["composeUsers"]["totalCount"] += tmp["user"] if tmp else 0
        data["composeUsers"]["dayInfo"].append(
            {"count": tmp["user"] if tmp else 0, "time": begin_date}
        )

        # -----------------------------------------------------------------------
        # pay = obj.paycase(
        #     dic["caseId"],
        #     datetime.strptime(begin_date, "%Y-%m-%d"),
        #     datetime.strptime(deviation_date(begin_date, +1), "%Y-%m-%d"),
        #     limit=limit
        # )
        # pay_dic = {eq['time']: {"user": eq['user'], "money": eq['money'], "count": eq['count']} for eq in pay_list}
        tmp = pay_dic.get(begin_date)
        # data["payVideos"]["totalCount"] += len(pay)
        data["payVideos"]["totalCount"] += tmp["count"] if tmp else 0
        data["payVideos"]["dayInfo"].append({"count": tmp["count"] if tmp else 0, "time": begin_date})
        # payuser = []
        # cashFeeall = 0

        # for i in pay:
        #     cashFeeall += i["totalFee"] / 100
        #     if i["openId"] not in payuser:
        #         payuser.append(i["openId"])

      
        data["payUsers"]["totalCount"] += tmp["user"] if tmp else 0
        data["payUsers"]["dayInfo"].append({"count": tmp["user"] if tmp else 0, "time": begin_date})

      
        data["cashFee"]["totalCount"] += round(tmp["money"]/100,2) if tmp else 0
        # cashFeeall = round(cashFeeall, 2)
        data["cashFee"]["totalCount"] = round(data["cashFee"]["totalCount"], 2)
        data["cashFee"]["dayInfo"].append({"count": round(tmp["money"]/100,2) if tmp else 0, "time": begin_date})

    
        begin_date = deviation_date(begin_date, +1)

    return response.make_response_success(data)


@record_module.route("/tem/<int:caseId>", methods=["POST"])
def tem_caseId(caseId):
 
    dic = json.loads(request.data)

    now = datetime.now().strftime("%Y-%m-%d")
    cache = redis.Redis(host='10.206.0.115', port=6379, db=10, password='SKadmin123_456')
    t1 = cache.get(request.headers["Authorization"])
    playground_limit = ""
    if t1:
        admin_id = int(t1)
        obj = pgadmin.PgAdmin()
        user_dic = obj.get(admin_id)
        playground_limit = user_dic['playground_limit']
    # payobj.payoperatortime(operatorId, now, deviation_date(now, +1))
    # ret[0]["count"] = payobj.payoperatortime(
    #     operatorId,
    #     datetime.strptime(now, "%Y-%m-%d"),
    #     datetime.strptime(deviation_date(now, +1), "%Y-%m-%d"),
    # )["count"]
    obj = record.PgRecord()
    res = {"compose": [], "pay": []}
    composeres = obj.temonecompose(
        caseId,
        datetime.strptime(dic[0], "%Y-%m-%d"),
        datetime.strptime(deviation_date(dic[1], +1), "%Y-%m-%d"),
    )
    for i in composeres:
        if i["templateId"] != None :
            if playground_limit :
                if playground_limit in i['templateName']:
                    res["compose"].append(i)
            else:
                res["compose"].append(i)
    payres = obj.temonepay(
        caseId,
        datetime.strptime(dic[0], "%Y-%m-%d"),
        datetime.strptime(deviation_date(dic[1], +1), "%Y-%m-%d"),
    )
    for i in payres:
        if i["templateId"] != None:
            if playground_limit :
                if playground_limit in i['templateName']:
                    res["pay"].append(i)
            else:
                res["pay"].append(i)

    return response.make_response_success(res)




@record_module.route("/recordbytime", methods=["POST"])
@urlcost.cost_count_wraps
def record_time():
   
    dic = json.loads(request.data)
    obj = record.PgRecord()
    res = ""
    if dic['caseId']:
        res = obj.casebytime(dic['caseId'],dic['time'][0],dic['time'][1])
    else:
        res = obj.allbytime(dic['time'][0],dic['time'][1])
    if(res):
        return response.make_response_success(res)
    else:
        return response.make_response_1000()



@record_module.route("/techpaybytime", methods=["POST"])
@urlcost.cost_count_wraps
def techpay_time():

    dic = json.loads(request.data)
    obj = pgtechpay.Pgtechpay()
    res = ""
    if dic['caseId']:
        res = obj.casebytime(dic['caseId'],dic['time'][0],dic['time'][1])
    else:
        res = obj.allbytime(dic['time'][0],dic['time'][1])
    if(res):
        return response.make_response_success(res)
    else:
        return response.make_response_1000()


@record_module.route("/cashFee/<int:caseId>", methods=["GET"])
@token.login_required
@urlcost.cost_count_wraps
def cashFee_cadrId(caseId):
  

    obj = record.PgRecord()
    pay = obj.paycashFeecase(caseId)
    cashFeeall = 0 

    for i in pay:
        cashFeeall += i["totalFee"] / 100
    cashFeeall = round(cashFeeall, 2)

    return response.make_response_success({"cashFee": cashFeeall})


@record_module.route("/paybytime", methods=["POST"])
def paybytime():


    obj = pgtechpay.Pgtechpay()
    dic = json.loads(request.data)
    pay = obj.paybytime(
        datetime.strptime(dic[0], "%Y-%m-%d"),
        datetime.strptime(deviation_date(dic[1], +1), "%Y-%m-%d"),
    )

    return response.make_response_success(pay)


# @record_module.route("/operator/<int:operatorId>", methods=["GET"])
# @token.login_required
# @urlcost.cost_count_wraps
# def operator(operatorId):
#     """
#     
#     """
#     obj = record.PgRecord()
#     res = obj.allOperator(operatorId)
#     return response.make_response_success(res)


# @record_module.route("/case/<int:caseId>", methods=["GET"])
# @token.login_required
# @urlcost.cost_count_wraps
# def case(caseId):
#     """
#  
#     """
#     obj = record.PgRecord()
#     res = obj.allCase(caseId)
#     return response.make_response_success(res)

